package com.zifeng.exception;

import static com.zifeng.exception.ErrorCodeAndMsg.*;

public enum ErrorEnum {

    // 通用错误
    SYSTEM_ERROR(SYSTEM_ERROR_CODE, SYSTEM_ERROR_MSG),
    PARAM_ERROR(PARAM_ERROR_CODE, PARAM_ERROR_MSG),

    // 用户相关错误
    USER_NOT_FOUND(USER_NOT_FOUND_CODE, USER_NOT_FOUND_MSG),
    USER_LOGIN_FAILED(USER_LOGIN_FAILED_CODE, USER_LOGIN_FAILED_MSG),
    USER_ACCOUNT_MONEY_NOT_ENOUGH(USER_ACCOUNT_MONEY_NOT_ENOUGH_CODE, USER_ACCOUNT_MONEY_NOT_ENOUGH_MSG),

    // 订单相关错误
    ORDER_NOT_FOUND(ORDER_NOT_FOUND_CODE, ORDER_NOT_FOUND_MSG),
    ORDER_CREATE_FAILED(ORDER_CREATE_FAILED_CODE, ORDER_CREATE_FAILED_MSG),
    ORDER_FEIGN_ADD_FAIL(ORDER_FEIGN_ADD_FAIL_CODE, ORDER_FEIGN_ADD_FAIL_MSG),
    ORDER_FEIGN_SELECT_BY_ID_FAIL(ORDER_FEIGN_SELECT_BY_ID_FAIL_CODE, ORDER_FEIGN_SELECT_BY_ID_FAIL_MSG),

    // 区块链相关错误
    BLOCK_CREATE_FAIL(BLOCK_CREATE_FAIL_CODE, BLOCK_CREATE_FAIL_MSG),
    BLOCK_FEIGN_CREATE_FAIL(BLOCK_FEIGN_CREATE_FAIL_CODE, BLOCK_FEIGN_CREATE_FAIL_MSG),

    // 任务委托相关错误
    ASSIGNMENT_FEIGN_UPDATE_FAIL(ASSIGNMENT_FEIGN_UPDATE_FAIL_CODE, ASSIGNMENT_FEIGN_UPDATE_FAIL_MSG);

    private final int code;
    private final String message;

    ErrorEnum(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    // 可选：带占位符格式化支持
    public String formatMessage(Object... args) {
        return String.format(this.message, args);
    }
}

